using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using Entities;
using DAL;
using Utility;
using BUS;

public partial class Admin_TTGiaoDich : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            LoadData();
        }
        if (Request.Url.ToString().Contains("dangnhap.aspx") == false && Session["tk"] == null)
            Response.Redirect("~/Admin/dangnhap.aspx");
    }
    private void LoadData()
    {
        Pager.PageSize = 5;
        Criteria c = new Criteria();
        if (txt_idgd.Text != "")
        {
            c.add(Condition.AND, tbTTGiaoDich .tbTTGiaoDichColumns.IDTTGiaoDich , Condition.LIKE,
                txt_idgd.Text);
        }
        if (txt_ttgd.Text != "")
        {
            c.add(Condition.AND,tbTTGiaoDich .tbTTGiaoDichColumns .GiaoDich , Condition.LIKE, txt_ttgd.Text);
        }
        int total = 0;
        tbTTGiaoDich.tbTTGiaoDichCollection  gd_Collection =
            tbTTGiaoDichBus .Get(c.Criter, Pager.CurrentIndex, Pager.PageSize,
           tbTTGiaoDich.tbTTGiaoDichColumns.IDTTGiaoDich .ToString(), OrderDirection.ASC.ToString(), out total);
        Repeater1.DataSource = gd_Collection;
        Repeater1.DataBind();
        Pager.ItemCount = total;
        if (total <= Pager.PageSize)
            Pager.Visible = false;
    }
    protected void Pager_Command(object sender, CommandEventArgs e)
    {
        Pager.CurrentIndex = int.Parse(e.CommandArgument.ToString());
        LoadData();
    }
    protected void Repeater1_ItemDataBound(object sender, RepeaterItemEventArgs e)
    {
        if (e.Item.ItemType == ListItemType.AlternatingItem ||
            e.Item.ItemType == ListItemType.Item)
        {

            tbTTGiaoDich gd_tbl = (tbTTGiaoDich)e.Item.DataItem;
            Literal lit_ttgd = (Literal)e.Item.FindControl("lit_ttgd");
            Literal lit_idgd = (Literal)e.Item.FindControl("lit_idgd");
            Literal lit_httt = (Literal)e.Item.FindControl("lit_httt");
            Literal lit_sotien = (Literal)e.Item.FindControl("lit_sotien");

            HyperLink hpl_Edit = (HyperLink)e.Item.FindControl("hpl_Edit");
            HiddenField hf_id = (HiddenField)e.Item.FindControl("hf_id");
            tbHTThanhToan  httt_tbl = tbHTThanhToanBus .GetByID(gd_tbl.IDHinhThuc );
            if (httt_tbl != null)
            {
                lit_httt.Text = httt_tbl.TenHinhThuc .ToString();
            }
            lit_ttgd.Text = gd_tbl.GiaoDich;
            lit_sotien.Text = gd_tbl.ThanhTien .ToString();
            lit_idgd.Text = gd_tbl.IDTTGiaoDich .ToString();

            hf_id.Value = gd_tbl.IDTTGiaoDich .ToString();

            hpl_Edit.NavigateUrl = "TTGiaoDichUpdate.aspx?id=" + gd_tbl.IDTTGiaoDich .ToString();


        }
    }
    protected void btn_Search_Click(object sender, EventArgs e)
    {
        LoadData();

    }
}
